package com.dabbo.starship.cell;

import java.rmi.RemoteException;

import com.dabbo.starship.interfaces.Block;
import com.dabbo.starship.interfaces.Cell;

public class CellEngineCore extends CellDefault {

	private static final long serialVersionUID = -356034435526749944L;
	protected static int MAX_POWER = -175;
	protected int maxThrust = 80;
	
	public CellEngineCore(Block parent) throws RemoteException {
		super(parent);
		this.cellType = Cell.CELL_ENGINE_CORE;
		this.cargoAllowed = false;
		this.passable = true;
		this.activated = false;
		this.powerOutput = 0;
		this.thrust = 0;
		
	}

	@Override
	public void activate() throws RemoteException {
		this.activated = true;
		int damageRate = (CellEngineCore.MAX_POWER / 200) * damage;
		this.powerOutput = CellEngineCore.MAX_POWER + damageRate;
	}

	@Override
	public void deActivate() throws RemoteException {
		this.activated = false;
		this.thrust = 0;
	}
	
	@Override
	public void tick() {
		if (damage > 60) {
			Double test = 30 + (Math.random() * 80);
			if (test < damage) {
				this.activated = false;
				this.powerOutput = 0;
				this.thrust = 0;
			}
		}
	}
	
	@Override
	public void setThrust(int thrust) throws RemoteException {
		if (thrust > this.maxThrust) {
			thrust = this.maxThrust;
		}
		if (thrust < 0) {
			thrust = 0;
		}
		this.thrust = thrust;
	}

	@Override
	public int getThrust() throws RemoteException {
		return this.thrust;
	}

	
}
